package com.example.child_protection.config;


import com.example.child_protection.intercetor.LoginIntercetor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.web.servlet.config.annotation.*;


@Configuration
public class LoginConfig implements WebMvcConfigurer {

    @Autowired
    private LoginIntercetor loginIntercetor;

    /** 解决跨域问题 **/
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").allowedHeaders("*")
                .allowedMethods("*")
                .allowedOrigins("*")
                .allowCredentials(true);
    }
    /** 添加拦截器 **/
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(loginIntercetor).addPathPatterns("/**");
    }
    /** 这里配置视图解析器 **/
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry){

    }
    /** 配置内容裁决的一些选项 **/
    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer){

    }
    /** 视图跳转控制器 **/
    @Override
    public  void addViewControllers(ViewControllerRegistry registry){

    }
    /** 静态资源处理 **/
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry){

    }
    /** 默认静态资源处理器 **/
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer){

    }
    /**
     * 自动转换时间格式
     *
     * @param registry date
     */
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addFormatter(new DateFormatter("yyyy-MM-dd HH:mm:ss"));
        registry.addFormatter(new DateFormatter("yyyy/MM/dd HH:mm:ss"));
        registry.addFormatter(new DateFormatter("yyyy-MM-dd"));
        registry.addFormatter(new DateFormatter("yyyy/MM/dd"));
    }

}
